<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends MY_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		//获取微信API信息
		$this->load->model('Syswxconfig_model');
		$wx_config = $this->Syswxconfig_model->get_wxconfig();
		// $this->smarty->assign("wx_config", $wx_config);
		// $this->smarty->assign("timestamp", time());

		require_once "third_party/wxjsapi/jssdk.php";
		$jssdk = new JSSDK($wx_config['appid'], $wx_config['appsecret'], $this->school_id);
		$signPackage = $jssdk->GetSignPackage();
		$this->smarty->assign("signPackage", $signPackage);

		// print_r($signPackage);exit;


		$this->smarty->assign("logged_in",$this->logged_in);
		$this->load->model('Courses');
		//获取网校信息
		$this->load->model('School_model');
		$school = $this->School_model->get_school_by_id($this->school_id);
		$this->smarty->assign("school", $school);

		//获取网课分类
		$cate_list = $this->Courses->get_cate_list();
		$this->smarty->assign("cate_list", $cate_list);

		//获取视频list
		$video_list = $this->Courses->get_recomend_course_list(4);
		$this->smarty->assign("video_list", $video_list);



		//获取一条直播
		$this->load->model('lives');
		$zhibo = $this->lives->get_last_zhibo();
		$time = time();
		if($zhibo['start_time'] < $time && $time < $zhibo['end_time']){
			$zhibo['live_status'] = 2;
		}
		if($zhibo['start_time'] > $time){
			$zhibo['live_status'] = 1;
		}
		if($zhibo['end_time'] < $time){
			$zhibo['live_status'] = 3;
		}
		$this->smarty->assign("zhibo", $zhibo);

		// print_r($zhibo);exit;

		//获取班课list
		$this->load->model("Courseo2o_model");
		$banke_list = $this->Courseo2o_model->get_banke_list($this->school_id,4);
		$this->smarty->assign("banke_list", $banke_list);

		$this->load->model('Advertisings');
        $ad_conditions['ad_position_sign'] = "wx-index-banner";
        $ad_conditions['school_id'] = $this->school_id;
        $banner_list = $this->Advertisings->get_list($ad_conditions);

        $this->smarty->assign("banner_list", $banner_list);

        $this->load->model("School_page_modulars");
        $have_modular = $this->School_page_modulars->get_school_page_modulars($this->school_id, 2);
        $have_modular_id = array_column($have_modular, "id");
        $this->smarty->assign("have_modular_id", $have_modular_id);

		$this->load->model("Newses");
        $new_list = $this->Newses->get_news10($this->school_id, 3);
        $this->smarty->assign("new_list", $new_list);

        $this->load->model("Friend_links");
        $index_friend_links = $this->Friend_links->get_friend_link_list(0, 4, array("school_id" => $this->school_id));
        $this->smarty->assign("index_friend_links", $index_friend_links);

		$this->smarty->assign("menu", "home");
		// $this->smarty->assign("user_data", $this->user_data);
		$this->smarty->display("index.html");
	}


}
